package com.imooc.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.imooc.exception.UserNotExitException;

/**
 * @ClassName ControllerExceptionHandler.java
 * @Description 处理其他控制器跑出的异常
 * @author Jon
 * @date 2018年5月29日 下午5:03:59
 */
@ControllerAdvice
public class ControllerExceptionHandler {
	
	@ExceptionHandler(UserNotExitException.class)//处理的异常的类
	@ResponseBody//返回json格式
	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)//处理的异常的状态码
	public Map<String, Object> handlerUserNotExitException(UserNotExitException ex) {
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("id", ex.getId());
		result.put("message", ex.getMessage());
		return result;
	}
}
